/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lianxishilili.demo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author Administrator
 */
public class Notices {
    private String getTodayName(){
        Date date=new Date();
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
        String dateString=formatter.format(date);
        return dateString;
    }
    private String getTomorrowName(){
        Date date=new Date();
        Calendar calendar=new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,1);
        date=calendar.getTime();
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
        String daString=formatter.format(date);
        return daString;
     }
    public  void getTodayNotices() {
        try{
            File file=new File("notice/"+getTodayName()+".txt");
            if(! file.exists()){
                 FileReader f=new FileReader(file);
                 BufferedReader br=new BufferedReader(f);
                 String temp=null;
                 while((temp=br.readLine())!=null){
                     System.out.println(temp);
                 }
                
            }else{
                System.out.println("今天没有什么要提醒的。");
             }
        }catch(Exception ex){
            ex.printStackTrace();
         }
      }
    public boolean setTomorrowNotice(String notice){
    try{
        File file=new File("notice");
        if(!file.exists()){
            file.mkdir();
         }
        file=new File("notice/"+getTomorrowName()+".txt");
        if(!file.exists()){
            file.createNewFile();
        }
        FileOutputStream f=new FileOutputStream(file,true);
        PrintWriter p=new PrintWriter(f,true);
        p.println(notice);
        System.out.println("成功添加一条明天的备忘录信息");
     }catch(Exception ex){
         ex.printStackTrace();
         return false;
     }
    return true;
     }
    public static void main(String[] args) throws IOException{
        Notices n=new Notices();
        String dateString=n.getTodayName();
        System.out.println(dateString);
        String tomorrowString=n.getTomorrowName();
        System.out.println(tomorrowString);
        n.setTomorrowNotice("下午去武鸣。");
        n.setTomorrowNotice("12:00去开会。");
        
    }
   }
 
    

